import 'package:flutter/material.dart';

void main() {
  runApp(MainPage());
}
//父组件
class MainPage extends StatefulWidget {
  MainPage({Key? key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  List<String> _list = ["1","2","3","4","5","6","7","8","9","10"];
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home:Scaffold(
        body:GridView.count(crossAxisCount: 2,
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
        padding: EdgeInsets.all(10),
        children: List.generate(_list.length, (index) {
          return child(message:_list[index]);
        }))
      )
    );
  }
}

//子组件
class child extends StatefulWidget {
  final String message;
  child({Key? key,required this.message}) : super(key: key);

  @override
  _childState createState() => _childState();
}

class _childState extends State<child> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.blue,
      alignment: Alignment.center,
       child: Text("111-${widget.message}",
       style:TextStyle(color: Colors.white,fontSize: 20)),
    );
  }
}